package org.mspring.mlog.web.module.admin.system;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.mspring.mlog.web.module.admin.Admin_AbstractWidget;
import org.mspring.mlog.web.support.log.Log;
import org.mspring.platform.cache.CacheManager;
import org.mspring.platform.web.freemarker.widget.stereotype.Widget;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @author Gao Youbo
 * @since 2012-11-9
 */
@Widget
@RequestMapping("/admin/system/cache")
public class Admin_CacheWidget extends Admin_AbstractWidget {

    @Autowired
    private CacheManager cacheManager;

    @RequestMapping("/config")
    @Log
    public String setting(HttpServletRequest request, HttpServletResponse response, Model model) {
        return "/admin/system/cache/config";
    }

    @RequestMapping("/config/save")
    @Log
    public String saveSetting(@RequestParam String cache_prefix, HttpServletRequest request, HttpServletResponse response, Model model) {
        return "redirect:/admin/system/cache/config";
    }

    @RequestMapping("/clear")
    @Log
    public String doClear(HttpServletRequest request, HttpServletResponse response, Model model) {
        cacheManager.clearAll();
        return prompt(model, "缓存清理成功！");
    }
}
